<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MapUse extends CI_Controller 
{

	public function index()
	{
	$fb_config = array(
            'appId'  => '159703560804912',
            'secret' => 'aa4895d729ddfabf9c65395cf0be6390'
        );

        $this->load->library('facebook', $fb_config);
		$this->FB=$this->facebook;
        $user = $this->facebook->getUser();

        if ($user) {
            try {
                $data['user_profile'] = $this->facebook->api('/me');
                $data['facebook']=$this->facebook;
            } catch (FacebookApiException $e) {
                $user = null;
            }
        }

        if ($user) {
            $data['logout_url'] = $this->facebook->getLogoutUrl();
        } else {
            $data['login_url'] = $this->facebook->getLoginUrl();
        }
		$this->load->view('mapuse_view',$data);
	}
	function AJAX_update_places_facebook()
	{
			if(!isset($_POST['lat'])||!isset($_POST['lng'])||!isset($_POST['ratio']))
				return;	
			$lat=$_POST['lat'];
			$lng=$_POST['lng'];
			$ratio=$_POST['ratio'];
		

			//$a='-33.03551638333,-71.595061266667';
			
			$fb_config = array(
            'appId'  => '159703560804912',
            'secret' => 'aa4895d729ddfabf9c65395cf0be6390'
	        );
	
	        $this->load->library('facebook', $fb_config);
		
			$params = array(
		    'method' => 'fql.query',
	    	'scope' => 'user_status,publish_stream,user_photos',
		    'query' => "SELECT name,latitude,longitude FROM place WHERE distance(latitude, longitude,'$lat','$lng') < '$ratio'",
			);
		
			$result = $this->facebook->api($params);
			echo json_encode($result);

	}

}